package com.dingyang.config;

import com.dingyang.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author 晚点再动心
 * @Date 2022/8/29
 * 使用自定义的拦截器方法做登录时候的拦截器
 */
@Configuration
@Slf4j
public class WebAppConfig implements WebMvcConfigurer {


    @Bean
    public LoginInterceptor loginInterceptor(){
        return  new LoginInterceptor();
    }

    //注册登录拦截器
    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry){
        //登录拦截管理器
        InterceptorRegistration interceptorRegistration = interceptorRegistry.addInterceptor(loginInterceptor());

        //配置需要拦截的路径
        interceptorRegistration.addPathPatterns("/**");

    }
}
